<?php
    /**
     * cms后台新闻修改管理页
     * author wang
     * mail:970633164@qq.com
     */

define("PHP_IN",true);
require "../include/init.php";
require "checklogin.php";
require ROOT_PATH."cms/smart_connection.php";

$page = isset($_GET['page']) ? $_GET['page'] : 1;
$newsid = isset($_GET['newsid'])? $_GET['newsid']:0;

if(isset($_POST['dosubmit'])){
    $title = $_POST['title'];
    $intro = $_POST['intro'];
    $isdisplay = intval($_POST['isdisplay']);
    $content = isset($_POST['editorValue']) ? $_POST['editorValue'] : "";
    if($title=="" || $intro=="" || $content==""){
        alert("请填写完整的文章内容");
        exit;
    }
    $newid = $_POST['newid'];
    $sql = "UPDATE news SET title='$title',intro='$intro',content='$content',isdisplay='$isdisplay' WHERE newsid = '$newid'";
    $result = $db->query($sql);
    if ($result) {
        alert("修改成功", "news_list.php?page=".$page);
    } else {
        alert("修改失败");
    }
}

if(isset($_GET['newsid'])){
    $sql = "SELECT * FROM news WHERE newsid = $newsid";
    $result = $db->query($sql);
    if($result && $db->num_rows($result)){
        $news = $db->fetch_one($result);
    }else{
        alert("该新闻已经不存在！","news_list.php");
    }
}else{
    alert("新闻不存在！","news_list.php");
}

$smarty->assign("news",$news);
$smarty->assign("page",$page);


$smarty->display("news_edit.tpl");
$db->close();
?>
